unit uAppConfig;

interface

uses
  SysUtils, uDZPersistent;

type
  TAppConfig = class(TPersistent)
  private
    fListenPort: Word;
    fSmsAccountName: string;
    fSmsPassword: string;
  public
    constructor Create(); override;
    destructor Destroy(); override;
  published
    property ListenPort: Word read fListenPort write fListenPort;
    property SmsAccountName: string read fSmsAccountName write fSmsAccountName;
    property SmsPassword: string read fSmsPassword write fSmsPassword;
  end;

function AppConfig(): TAppConfig;

implementation

uses
  ActiveX;

var
  AppConfig: TAppConfig;

function AppConfig(): TAppConfig;
begin
  Result := AppConfig;
end;

{ TAppConfig }

constructor TAppConfig.Create();
var
  ConfigFileName: string;
begin
  inherited;
  ConfigFileName := ExtractFilePath(ParamStr(0)) + 'settings.conf';
  if FileExists(ConfigFileName) then LoadFromFile(ConfigFileName, afXML);
  if fListenPort = 0 then fListenPort := 8080;
end;

destructor TAppConfig.Destroy();
begin
  SaveToFile(ExtractFilePath(ParamStr(0)) + 'settings.conf', afXML);
  inherited;
end;

initialization
  CoInitialize(nil);
  AppConfig := TAppConfig.Create();

finalization
  AppConfig.Free();
  CoUninitialize();

end.
